<!-- 通知方式 -->
<template>
  <div class="bg-white dialog-form-container q-px-md">
    <span class="q-mr-lg">
      <q-checkbox
        dense
        v-model="creatUpdateQuery.is_system"
        label="系统通知"
        @update:model-value="changeSendWay('is_system')"
      />
    </span>
    <span class="q-mr-lg">
      <q-checkbox
        dense
        v-model="creatUpdateQuery.is_email"
        label="邮件通知"
        @update:model-value="changeSendWay('is_email')"
      />
    </span>
    <!-- <span class="q-mr-lg">
      <q-checkbox
        dense
        v-model="creatUpdateQuery.is_sms"
        label="短信通知"
        @update:model-value="changeSendWay('is_sms')"
      />
    </span> -->
    <span>
      <q-checkbox
        dense
        v-model="creatUpdateQuery.is_wechat"
        label="微信公众号通知"
        @update:model-value="changeSendWay('is_wechat')"
      />
    </span>
  </div>
</template>

<script>
import { getWarnNotice, setNoticeWay } from "src/api/systemtWarning"
export default {
  data () {
    return {
      creatUpdateQuery: {
        receiver_name: '',
        is_system: false,
        is_sms: false,
        is_wechat: false,
        is_email: false
      },
      receiverType: [
        { value: '系统通知', label: '系统通知', key: 'is_system' },
        { value: '邮件通知', label: '邮件通知', key: 'is_email' },
        // { value: '短信通知', label: '短信通知', key: 'is_sms' },
        { value: '微信公众号通知', label: '微信公众号通知', key: 'is_wechat' }
      ]
    };
  },

  components: {},

  computed: {},

  mounted() {
    this.getWayInfo()
  },

  methods: {
    // 获取告警通知方式的信息
    getWayInfo() {
      getWarnNotice({ receiver_uid: localStorage.getItem('user_id_GFYW') }).then(res => {
        const { status, data } = res
        if (status === 200) {
          this.creatUpdateQuery = Object.assign({}, data)
          this.receiverType.forEach(element => {
            const _t = this.creatUpdateQuery[element.key]
            if (_t) {
              this.creatUpdateQuery.type_name = element
            }
          })
        }
      })
    },
    // 修改告警通知方式的信息
    updateSendWay(queryWay) {
      setNoticeWay(this.creatUpdateQuery.id, queryWay).then(res => {
        const { status, data } = res
        if (status === 200) {
          this.getWayInfo()
          this.$q.notify({
            position: 'top',
            type: 'positive',
            message: '修改成功！'
          })
        }

      })
    },
    // 处理发送的方法
    changeSendWay(val) {
      let _query = {}
      if (val) {
        _query[val] = this.creatUpdateQuery[val]
        this.updateSendWay(_query)
      }
    }
  }
}

</script>
<style lang='scss' scoped>
.dialog-form-container {
  height: 90px;
  line-height: 90px;
  overflow: auto;
}
</style>
